import Vue from 'vue'
import VueRouter from 'vue-router'
import iphone_store from "@/views/mobile/user/store/Iphone_store";
import addressList from "@/views/mobile/user/store/AddressList";
import addressNew from "@/views/mobile/user/store/AddressNew";
import addressEdit from "@/views/mobile/user/store/AddressEdit";
import detail from "@/views/mobile/user/store/Detail"
import success from "@/views/mobile/user/store/Success"
import info from "@/views/mobile/user/store/Info"
Vue.use(VueRouter)

/**
 * 自行配置路由*
 *
 * @author LWG
 * @date 2022/7/19 14:28
 * @since 1.0.0
 */
const routes = [
//Vip详情页
{
  path: '/vip',
  name: 'VipPage',
  component: () => import('../views/mobile/user/VipPage.vue'),
},

  /***
   * DJ*/
  //订单详情
  {
    path: '/info',
    name: '订单详情',
    component: info,
  },

  /***
   * DJ*/
  //订单
  {
    path: '/success',
    name: '订单',
    component: success,
  },

  /***
   * DJ*/
  //订单
  {
    path: '/detail',
    name: '订单',
    component: detail,
  },

    /***
     * DJ*/
  //编辑地址
  {
    path: '/addressEdit',
    name: '编辑地址',
    component: addressEdit,
  },

  /***
   * DJ*/
  //新增地址
  {
    path: '/addressNew',
    name: '新增地址',
    component: addressNew,
  },

  /***
   * DJ*/
  //地址列表
  {
    path: '/addressList',
    name: '地址列表',
    component: addressList,
  },

  /***
   * DJ*/
  //商城首页
  {
    path: '/iphoneStore',
    name: '商城首页',
    component: iphone_store,
  },
  //求助详情页
{
  path: '/homeview/help/helppage/helpdetails',
  name: 'HelpDetails',
  component: () => import('../views/mobile/user/HelpDetails.vue'),
},

  //分享详情页
  {
    path: '/homeview/share/sharepage/sharedetails',
    name: 'ShareDetails',
    component: () => import('../views/mobile/user/ShareDetails.vue'),
  },

    //聊天页面
  {
    path: '/homeview/message/messagePage/userChat',
    name: 'UserChat',
    component: () => import('../views/mobile/home/UserChat')
  },

  //忘记密码
  {
    path: '/forgetpwd',
    name: 'ForgetPassword',
    component: () => import('../views/mobile/user/ForgetPassword.vue'),
  },

  //主页分享，求助路由，三级路由
  {
    // 底部栏
    path: '/homeview',
    name: 'HomeView',
    component: () => import('../views/HomeView.vue'),
    // 分享嵌套
    children: [{
      path: 'share',
      name: 'Share',
      component: () => import('../views/mobile/home/Share.vue'),
      children: [{
        path: 'Sharepage',
        name: 'SharePage',
        component:()=>import('../views/mobile/home/SharePage.vue')
      }]
    }, {
      // 求助嵌套
      path: 'help',
      name: 'Help',
      component: () => import('../views/mobile/home/Help.vue'),
      children: [{
        path: 'helppage',
        name: 'HelpPage',
        component:()=>import('../views/mobile/home/HelpPage.vue')
      }]
      }, {
        // 我的嵌套
      path: 'my',
      name: 'My',
      component: () => import('../views/mobile/home/My.vue'),
      children: [{
        path: 'mypage',
        name: 'MyPage',
        component: () => import('../views/mobile/home/MyPage.vue'),
        }]
      },{
      //消息嵌套
      path: 'message',
      name: 'Message',
      component: () => import('../views/mobile/home/Message'),
      children: [{
        path: 'messagePage',
        name: 'messagePage',
        component: () => import('../views/mobile/home/MessagePage')
      }]
    },{
      path: 'indexView',
      name: 'indexView',
      component: ()=>import('../views/mobile/home/IndexView')
    }]
  },
    //登录页面
  // {
  //   path: '/login',
  //   name: 'login',
  //   component: () => import('../views/mobile/user/Login'),
  // },
    //注册页面
  {
    path: '/registry',
    name: 'registry',
    component: () => import('../views/mobile/user/Registry'),
  },
  {
    path: '/registry/detail',
    name: 'Registry0',
    component: () => import('@/views/mobile/user/Registry0')
  },
  {
    path: '/homeview/my/mypage/edit',
    name: 'Edit',
    component: () => import('@/views/mobile/user/Edit')
  },
  //积分任务
  {
    path: '/homeview/my/mypage/IntegralTaskTest',
    name: 'Edit',
    component: () => import('@/views/mobile/home/IntegralTaskTest')
  },
  //默认路由
  {
    path: "/",
    redirect:'/homeview/share/sharepage',
  },



  //测试部分路由，后期删除
  //测试关注页
  {
    path: '/homeview/my/mypage/personalPage/follow',
    name: 'follow',
    component: () => import('../views/mobile/user/Follow'),
  },
  //测试设置页
  {
    path: '/setting',
    name: 'Setting',
    component: () => import('../views/mobile/user/Settings.vue'),
  },
  //测试发布页
  {
    path: '/posthelp',
    name: 'PostHelp',
    component: () => import('../views/mobile/user/PostHelp'),
  },
    {
    path: '/homeview/share/sharepage/postshare',
    name: 'PostShare',
    component: () => import('../views/mobile/user/PostShare.vue'),
  },
    {
    path: '/homeview/my/mypage/personalPage',
    name: 'PersonalHomePage',
    component: () => import('../views/mobile/user/PersonalHomepage'),
  },
  //测试求助路由
  {
    path: '/testhelpbar',
    name: 'Helpbar',
    component: () => import('../testing/Helpbar.vue'),
  },
  //测试搜索路由
  {
    path: '/testsharebar',
    name: 'TestSharebar',
    component: () => import('../testing/Sharebar.vue'),
  },
  //测试底部导航栏路由
  {
    path: '/testtabbar',
    name: 'TestTabbar',
    component: () => import('../testing/Tabbar.vue'),
  },
  //测试我的页面头
  {
    path: '/testmy',
    name: 'TestMy',
    component: () => import('../testing/TestMy.vue'),
  },
  // 测试登录页
  {
    path: '/testlogin',
    name: 'Login',
    component: () => import('../testing/IndexView.vue'),
  },
  //测试顶部导航栏
  {
    path: '/testnavbar',
    name: 'TestNavbar',
    component: () => import('../testing/Navbar.vue'),
  },
  //测试细节内容
    {
    path: '/testdetails',
    name: 'TestDetails',
    component: () => import('../testing/Details.vue'),
  },
    //测试vip页面
    {
      path: '/testvip',
      name: 'TestVip',
      component: () => import('../testing/Vip.vue'),
  },
    /*{
      path: '/personaltest',
      name: 'PersonalHomrpageTest',
      component: () => import('../views/mobile/user/PersonalHomepage'),
    },*/
  {
    path: '/indexView',
    name: 'indexView',
    component: ()=>import('../views/mobile/home/IndexView')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  scrollBehavior(to, from, savedPosition) {
    return { x: 0, y: 0}
  },
})

to:即将进入的路由对象
from:当前导航即将离开额路由
next:进行管道中的一个钩子，如果执行完了，那么导航的状态就是 confirmed，否则为false，终止导航

router.beforeEach((to, from, next) => {
    console.log(this)
    if (to.path === '/login') {
        //如果去登录页面，就放行
        next();
    } else if (JSON.parse(localStorage.getItem("user")) != null) {
        console.log(JSON.parse(localStorage.getItem("user")))
        //如果登录了，就放行
        next();
    } else {
        //如果没有登录，那么就跳转带登录页面
        next("/login");
    }
})

export default router
